package com.zt.ztyh.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zt.ztyh.dto.LoanDto;
import com.zt.ztyh.dto.LoanUser;
import com.zt.ztyh.entity.User;
import com.zt.ztyh.entity.ZtyhLoanUser;
import com.zt.ztyh.service.ZtyhLoanUserService;
import com.zt.ztyh.vo.loan.LoanVo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/ztyh/loanUser")
public class LoanUserController {

    /**
     * 添加贷款项
     * 参数就是中间表的对象
     * 返回值 boolean
     * @return
     */
    @Autowired
    private ZtyhLoanUserService ztyhLoanUserService;

    //添加贷款
    @PostMapping("/addLoan")
    @Operation(summary = "添加贷款信息")
    public boolean addLoan(@RequestBody LoanUser loanUser){
      return this.ztyhLoanUserService.addLoan(loanUser);
    }

    //查询个人所贷款信息
    @PostMapping("/findUserLoan")
    @Operation(summary = "根据用户id查询贷款信息")
    public Page<LoanVo> findUserLoan(@RequestBody LoanDto loanDto){
        return this.ztyhLoanUserService.findUserLoan(loanDto);
    }

    @GetMapping("/findUserLoanLimit/{uid}")
    @Operation(summary = "根据用户id查询贷款额度")
    public BigDecimal findUserLoanLimit(@PathVariable("uid") Long uid){
        return this.ztyhLoanUserService.findUserLoanLimit(uid);
    }

    @GetMapping("/getById/{id}")
    @Operation(summary = "根据id查询贷款信息")
    public LoanUser getById(@PathVariable("id") Long id){
        return this.ztyhLoanUserService.findById(id);
    }

    @PutMapping("/updateById")
    @Operation(summary = "根据id更新贷款信息")
    public boolean updateById(@RequestBody LoanUser loanUser){
        return this.ztyhLoanUserService.updateLoanById(loanUser);
    }

    @GetMapping("/findUserInfo/{uid}")
    @Operation(summary = "根据用户id查询用户信息")
    public User findUserInfo(@PathVariable("uid") Long uid){
        return this.ztyhLoanUserService.findUserInfo(uid);
    }
}
